package cn.fintecher.pangolin.service.dataimp.web;

import cn.fintecher.pangolin.common.enums.ImportTemplateType;
import cn.fintecher.pangolin.common.model.UploadFile;
import cn.fintecher.pangolin.common.web.BaseController;
import cn.fintecher.pangolin.entity.elastic.*;
import cn.fintecher.pangolin.service.dataimp.request.*;
import cn.fintecher.pangolin.service.dataimp.response.FindDistributeCaseResponse;
import cn.fintecher.pangolin.service.dataimp.response.FindImportResponse;
import cn.fintecher.pangolin.service.dataimp.service.DataImportService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

/**
 * @Auther: xiaqun
 * @Description: 数据导入相关接口
 * @Date: 16:27 2019/8/26
 */

@RestController
@RequestMapping("/api/dataImportController")
@Api(value = "数据导入相关接口", description = "数据导入相关接口")
public class DataImportController extends BaseController {
    @Autowired
    private DataImportService dataImportService;

    /**
     * 导入案件结果查询
     */
    @ApiOperation(value = "导入案件结果查询", notes = "导入案件结果查询")
    @GetMapping("/findAllDataImportResult")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<DataImportRecord>> findAllDataImportResult(FindDataImportRequest request, Pageable pageable,
                                                                          @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to find all data import result,{}", request);
        Page<DataImportRecord> page = dataImportService.findAllDataImportResult(request, pageable, token);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 案件导入
     */
    @ApiOperation(value = "案件导入", notes = "案件导入")
    @PostMapping("/importCase")
    public ResponseEntity<Void> importCase(@Valid @RequestBody ImportCaseRequest request,
                                           @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to import case,{}", request);
        dataImportService.importCase(request, token, ImportTemplateType.CASE_IMPORT);
        return ResponseEntity.ok().build();
    }

    /**
     * 取消导入
     */
    @ApiOperation(value = "取消导入", notes = "取消导入")
    @GetMapping("/cancelImport")
    public ResponseEntity<Void> cancelImport(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                             @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel import,{}", id);
        dataImportService.cancelImport(id, token, ImportTemplateType.CASE_IMPORT);
        return ResponseEntity.ok().build();
    }

    /**
     * 导入详情查询
     */
    @ApiOperation(value = "导入详情查询", notes = "导入详情查询")
    @GetMapping("/findImportByBatchNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<FindImportResponse>> findImportByBatchNumber(@Valid FindImportRequest request, Pageable pageable) {
        log.info("REST request to find import by batch number,{}", request);
        Page<FindImportResponse> page = dataImportService.findImportByBatchNumber(request, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 案件导入确认
     */
    @ApiOperation(value = "案件导入确认", notes = "案件导入确认")
    @GetMapping("/confirmCase")
    public ResponseEntity<Void> confirmCase(@RequestParam @ApiParam(value = "案件导入记录ID", required = true) String id,
                                            @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to confirm case,{}", id);
        dataImportService.confirmCase(id, token, ImportTemplateType.CASE_IMPORT);
        return ResponseEntity.ok().build();
    }

    /**
     * 待分配案件多条件查询
     */
    @ApiOperation(value = "待分配案件多条件查询", notes = "待分配案件多条件查询")
    @GetMapping("/findDistributeCase")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<FindDistributeCaseResponse>> findDistributeCase(FindDistributeCaseRequest request, Pageable pageable,
                                                                               @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to find distribute case,{}", request);
        Page<FindDistributeCaseResponse> page = dataImportService.findDistributeCase(request, pageable, token);
        return ResponseEntity.ok().body(page);
    }

    @ApiOperation(value = "结清案件查询", notes = "结清案件查询")
    @GetMapping("/findSettleCase")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<FindDistributeCaseResponse>> findSettleCase(SettleCaseRequest settleCaseRequest, Pageable pageable,@RequestHeader(value = "X-UserToken") String token) {
        Page<FindDistributeCaseResponse> page = dataImportService.findSettleCase(settleCaseRequest, pageable, token);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 案件更新导入
     */
    @ApiOperation(value = "案件更新导入", notes = "案件更新导入")
    @PostMapping("/importCaseUpdate")
    public ResponseEntity<Void> importCaseUpdate(@Valid @RequestBody ImportCaseRequest request,
                                                 @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to import case update,{}", request);
        dataImportService.importCase(request, token, ImportTemplateType.CASE_UPDATE);
        return ResponseEntity.ok().build();
    }

    /**
     * 案件更新导入确认
     */
    @ApiOperation(value = "案件更新导入确认", notes = "案件更新导入确认")
    @GetMapping("/confirmUpdateCase")
    public ResponseEntity<Void> confirmUpdateCase(@RequestParam @ApiParam(value = "案件导入记录ID", required = true) String id,
                                                  @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to confirm update case,{}", id);
        dataImportService.confirmCase(id, token, ImportTemplateType.CASE_UPDATE);
        return ResponseEntity.ok().build();
    }

    /**
     * 默认模板ID返回
     */
    @ApiOperation(value = "默认模板ID返回", notes = "默认模板ID返回")
    @GetMapping("/getTemplateId")
    public ResponseEntity<UploadFile> getTemplateId(@RequestParam @ApiParam(value = "模板类型") ImportTemplateType type) {
        log.info("REST request to get template,{}", type);
        UploadFile uploadFile = dataImportService.getTemplateId(type);
        return ResponseEntity.ok().body(uploadFile);
    }

    /**
     * 对账单导入
     */
    @ApiOperation(value = "对账单导入", notes = "对账单导入")
    @PostMapping("/importBill")
    public ResponseEntity<Void> importBill(@Valid @RequestBody ImportCommonRequest request,
                                           @RequestHeader(value = "X-UserToken") String token) throws IOException {
        log.info("REST request to import bill,{}", request);
        dataImportService.importCommon(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 取消导入对账单
     */
    @ApiOperation(value = "取消导入对账单", notes = "取消导入对账单")
    @GetMapping("/cancelImportBill")
    public ResponseEntity<Void> cancelImportBill(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                 @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel import bill,{}", id);
        dataImportService.cancelImport(id, token, ImportTemplateType.BILL_IMPORT);
        return ResponseEntity.ok().build();
    }

    /**
     * 对账单详情查询
     */
    @ApiOperation(value = "对账单详情查询", notes = "对账单详情查询")
    @GetMapping("/findImportBillByBatchNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<PaymentRecordModel>> findImportBillByBatchNumber(FindBillRequest request,
                                                                                Pageable pageable) {
        log.info("REST request to find import bill by batch number,{}", request);
        Page<PaymentRecordModel> page = dataImportService.findImportBillByBatchNumber(request, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 对账单导入确认
     */
    @ApiOperation(value = "对账单导入确认", notes = "对账单导入确认")
    @GetMapping("/confirmImportBill")
    public ResponseEntity<Void> confirmImportBill(@RequestParam @ApiParam(value = "案件导入记录ID", required = true) String id,
                                                  @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to confirm import bill,{}", id);
        dataImportService.confirmImportBill(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 对账单单个撤销
     */
    @ApiOperation(value = "对账单单个撤销", notes = "对账单单个撤销")
    @GetMapping("/cancelBillImport")
    public ResponseEntity<Void> cancelBillImport(@RequestParam @ApiParam(value = "对账单导入模型ID", required = true) String id,
                                                 @RequestParam @ApiParam(value = "导入结果ID", required = true) String recordId,
                                                 @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel bill import,{},{}", id, recordId);
        dataImportService.cancelBillImport(id, recordId, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 对账单批量撤销
     */
    @ApiOperation(value = "对账单批量撤销", notes = "对账单批量撤销")
    @GetMapping("/cancelBatchBillImport")
    public ResponseEntity<Void> cancelBatchBillImport(@RequestParam @ApiParam(value = "对账单导入批次号", required = true) String batchNumber,
                                                      @RequestParam @ApiParam(value = "导入结果ID", required = true) String recordId,
                                                      @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel batch bill import,{},{}", batchNumber, recordId);
        dataImportService.cancelBatchBillImport(batchNumber, recordId, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 委前催记导入
     */
    @ApiOperation(value = "委前催记导入", notes = "委前催记导入")
    @PostMapping("/importPreRecord")
    public ResponseEntity<Void> importPreRecord(@Valid @RequestBody ImportCommonRequest request,
                                                @RequestHeader(value = "X-UserToken") String token) throws IOException {
        log.info("REST request to import pre record,{}", request);
        dataImportService.importCommon(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 委前催记取消导入
     */
    @ApiOperation(value = "委前催记取消导入", notes = "委前催记取消导入")
    @GetMapping("/cancelImportPreRecord")
    public ResponseEntity<Void> cancelImportPreRecord(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                      @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel import pre record,{}", id);
        dataImportService.cancelImport(id, token, ImportTemplateType.PRE_RECORD_IMPORT);
        return ResponseEntity.ok().build();
    }

    /**
     * 委前催记详情查询
     */
    @ApiOperation(value = "委前催记详情查询", notes = "委前催记详情查询")
    @GetMapping("/findImportPreByBatchNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<PreRecordModel>> findImportPreByBatchNumber(FindPreRecordRequest request,
                                                                           Pageable pageable) {
        log.info("REST request to find import pre by batch number,{}", request);
        Page<PreRecordModel> page = dataImportService.findImportPreByBatchNumber(request, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 委前催记导入确认
     */
    @ApiOperation(value = "委前催记导入确认", notes = "委前催记导入确认")
    @GetMapping("/confirmImportPreRecord")
    public ResponseEntity<Void> confirmImportPreRecord(@RequestParam @ApiParam(value = "案件导入记录ID", required = true) String id,
                                                       @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to confirm import pre record,{}", id);
        dataImportService.confirmImportPreRecord(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 委前催记导入撤销
     */
    @ApiOperation(value = "委前催记导入撤销", notes = "委前催记导入撤销")
    @GetMapping("/cancelBatchPreImport")
    public ResponseEntity<Void> cancelBatchPreImport(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                     @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel batch pre import,{}", id);
        dataImportService.cancelBatchImport(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 工单导入
     */
    @ApiOperation(value = "工单导入", notes = "工单导入")
    @PostMapping("/importWorkOrder")
    public ResponseEntity<Void> importWorkOrder(@Valid @RequestBody ImportCommonRequest request,
                                                @RequestHeader(value = "X-UserToken") String token) throws IOException {
        log.info("REST request to import work order,{}", request);
        dataImportService.importCommon(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 警告导入
     */
    @ApiOperation(value = "警告导入", notes = "警告导入")
    @PostMapping("/importWarning")
    public ResponseEntity<Void> importWarning(@Valid @RequestBody ImportCommonRequest request,
                                              @RequestHeader(value = "X-UserToken") String token) throws IOException {
        log.info("REST request to import warning,{}", request);
        dataImportService.importCommon(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 工单详情查询
     */
    @ApiOperation(value = "工单详情查询", notes = "工单详情查询")
    @GetMapping("/findImportWorkByBatchNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<WorkOrderModel>> findImportWorkByBatchNumber(FindWorkRequest request, Pageable pageable) {
        log.info("REST request to find import work by batch number,{}", request);
        Page<WorkOrderModel> page = dataImportService.findImportWorkByBatchNumber(request, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 警告详情查询
     */
    @ApiOperation(value = "警告详情查询", notes = "警告详情查询")
    @GetMapping("/findImportWarningByBatchNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<WarningModel>> findImportWarningByBatchNumber(FindWarningRequest request, Pageable pageable) {
        log.info("REST request to find import warning by batch number,{}", request);
        Page<WarningModel> page = dataImportService.findImportWarningByBatchNumber(request, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 工单取消导入
     */
    @ApiOperation(value = "工单取消导入", notes = "工单取消导入")
    @GetMapping("/cancelImportWorkOrder")
    public ResponseEntity<Void> cancelImportWorkOrder(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                      @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel import work order,{}", id);
        dataImportService.cancelImport(id, token, ImportTemplateType.WORK_ORDER_IMPORT);
        return ResponseEntity.ok().build();
    }

    /**
     * 警告取消导入
     */
    @ApiOperation(value = "警告取消导入", notes = "警告取消导入")
    @GetMapping("/cancelImportWarning")
    public ResponseEntity<Void> cancelImportWarning(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                    @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request tot cancel import warning,{}", id);
        dataImportService.cancelImport(id, token, ImportTemplateType.WARNING_IMPORT);
        return ResponseEntity.ok().build();
    }

    /**
     * 工单导入确认
     */
    @ApiOperation(value = "工单导入确认", notes = "工单导入确认")
    @GetMapping("/confirmImportWorkOrder")
    public ResponseEntity<Void> confirmImportWorkOrder(@RequestParam @ApiParam(value = "案件导入记录ID", required = true) String id,
                                                       @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request tp confirm import work order,{}", id);
        dataImportService.confirmImportWorkOrder(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 警告导入确认
     */
    @ApiOperation(value = "警告导入确认", notes = "警告导入确认")
    @GetMapping("/confirmImportWarning")
    public ResponseEntity<Void> confirmImportWarning(@RequestParam @ApiParam(value = "案件导入记录ID", required = true) String id,
                                                     @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to confirm import warning,{}", id);
        dataImportService.confirmImportWarning(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 工单导入撤销
     */
    @ApiOperation(value = "工单导入撤销", notes = "工单导入撤销")
    @GetMapping("/cancelBatchWorkImport")
    public ResponseEntity<Void> cancelBatchWorkImport(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                      @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel batch work import,{}", id);
        dataImportService.cancelBatchImport(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 警告导入撤销
     */
    @ApiOperation(value = "警告导入撤销", notes = "警告导入撤销")
    @GetMapping("/cancelBatchWarningImport")
    public ResponseEntity<Void> cancelBatchWarningImport(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                         @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel batch warning import,{}", id);
        dataImportService.cancelBatchImport(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 留案导入
     */
    @ApiOperation(value = "留案导入", notes = "留案导入")
    @PostMapping("/leaveImport")
    public ResponseEntity<Void> leaveImport(@Valid @RequestBody ImportCommonRequest request,
                                            @RequestHeader(value = "X-UserToken") String token) throws IOException {
        log.info("REST request ot leave import,{}", request);
        dataImportService.importCommon(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 停催导入
     */
    @ApiOperation(value = "停催导入", notes = "停催导入")
    @PostMapping("/stopImport")
    public ResponseEntity<Void> stopImport(@Valid @RequestBody ImportCommonRequest request,
                                           @RequestHeader(value = "X-UserToken") String token) throws IOException {
        log.info("REST request to stop import,{}", request);
        dataImportService.importCommon(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 留案导入详情查询
     */
    @ApiOperation(value = "留案导入详情查询", notes = "留案导入详情查询")
    @GetMapping("/findImportLeaveByBatchNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<LeaveCaseModel>> findImportLeaveByBatchNumber(FindCommonRequest request, Pageable pageable) {
        log.info("REST request to find import leave by batch number,{}", request);
        Page<LeaveCaseModel> page = dataImportService.findImportLeaveByBatchNumber(request, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 停催导入详情查询
     */
    @ApiOperation(value = "停催导入详情查询", notes = "停催导入详情查询")
    @GetMapping("/findImportStopByBatchNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<StopCaseModel>> findImportStopByBatchNumber(FindCommonRequest request, Pageable pageable) {
        log.info("REST request to find import stop by batch number,{}", request);
        Page<StopCaseModel> page = dataImportService.findImportStopByBatchNumber(request, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 留案取消导入
     */
    @ApiOperation(value = "留案取消导入", notes = "留案取消导入")
    @GetMapping("/cancelImportLeave")
    public ResponseEntity<Void> cancelImportLeave(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                  @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel import leave,{}", id);
        dataImportService.cancelImport(id, token, ImportTemplateType.LEAVE_IMPORT);
        return ResponseEntity.ok().build();
    }

    /**
     * 停催取消导入
     */
    @ApiOperation(value = "停催取消导入", notes = "停催取消导入")
    @GetMapping("/cancelImportStop")
    public ResponseEntity<Void> cancelImportStop(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                 @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel import stop,{}", id);
        dataImportService.cancelImport(id, token, ImportTemplateType.STOP_IMPORT);
        return ResponseEntity.ok().build();
    }

    /**
     * 留案导入确认
     */
    @ApiOperation(value = "留案导入确认", notes = "留案导入确认")
    @GetMapping("/confirmImportLeave")
    public ResponseEntity<Void> confirmImportLeave(@RequestParam @ApiParam(value = "案件导入记录ID", required = true) String id,
                                                   @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request tp confirm import leave,{}", id);
        dataImportService.confirmImportLeave(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 停催导入确认
     */
    @ApiOperation(value = "停催导入确认", notes = "停催导入确认")
    @GetMapping("/confirmImportStop")
    public ResponseEntity<Void> confirmImportStop(@RequestParam @ApiParam(value = "案件导入记录ID", required = true) String id,
                                                  @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request confirm import stop<{}", id);
        dataImportService.confirmImportStop(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 留案导入批量撤销
     */
    @ApiOperation(value = "留案导入批量撤销", notes = "留案导入批量撤销")
    @GetMapping("/cancelBatchLeaveImport")
    public ResponseEntity<Void> cancelBatchLeaveImport(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                       @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel import leave import,{}", id);
        dataImportService.cancelBatchImport(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 停催导入批量撤销
     */
    @ApiOperation(value = "停催导入批量撤销", notes = "停催导入批量撤销")
    @GetMapping("/cancelBatchStopImport")
    public ResponseEntity<Void> cancelBatchStopImport(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                      @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel batch stop import,{}", id);
        dataImportService.cancelBatchImport(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 分案导入
     */
    @ApiOperation(value = "分案导入", notes = "分案导入")
    @GetMapping("/importDistribute")
    public ResponseEntity<Void> importDistribute(@RequestParam @ApiParam(value = "文件ID", required = true) String fileId,
                                                 @RequestHeader(value = "X-UserToken") String token) throws IOException {
        log.info("REST request to import distribute,{}", fileId);
        dataImportService.importDistribute(fileId, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 下载分案导入模板
     */
    @ApiOperation(value = "下载分案导入模板", notes = "下载分案导入模板")
    @GetMapping("/downloadDistributeTemplate")
    public ResponseEntity<UploadFile> downloadDistributeTemplate() throws IOException {
        log.info("REST request to download distribute template");
        UploadFile uploadFile = dataImportService.downloadDistributeTemplate();
        return ResponseEntity.ok().body(uploadFile);
    }

    /**
     * 分案导入结果查询
     */
    @ApiOperation(value = "分案导入结果查询", notes = "分案导入结果查询")
    @GetMapping("/findAllDistributeRecord")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<DistributeImportRecord>> findAllDistributeRecord(FindDistributeRecordRequest request, Pageable pageable) {
        log.info("REST request to find all distribute record,{}", request);
        Page<DistributeImportRecord> page = dataImportService.findAllDistributeRecord(request, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 分案导入取消
     */
    @ApiOperation(value = "分案导入取消", notes = "分案导入取消")
    @GetMapping("/cancelImportDistribute")
    public ResponseEntity<Void> cancelImportDistribute(@RequestParam @ApiParam(value = "导入结果ID", required = true) String id,
                                                       @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to cancel import distribute,{}", id);
        dataImportService.cancelImportDistribute(id, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 分案导入详情查询
     */
    @ApiOperation(value = "分案导入详情查询", notes = "分案导入详情查询")
    @GetMapping("/findImportDistributeByBatchNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<DistributeModel>> findImportDistributeByBatchNumber(@RequestParam @ApiParam(value = "批次号", required = true) String batchNumber,
                                                                                   @RequestParam(required = false) @ApiParam(value = "案件编号") String caseNumber,
                                                                                   Pageable pageable) {
        log.info("REST request to find import distribute by batch number,{}", batchNumber, caseNumber);
        Page<DistributeModel> page = dataImportService.findImportDistributeByBatchNumber(batchNumber, caseNumber, pageable);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 分案导入确认
     */
    @ApiOperation(value = "分案导入确认", notes = "分案导入确认")
    @GetMapping("confirmImportDistribute")
    public ResponseEntity<Void> confirmImportDistribute(@RequestParam @ApiParam(value = "案件导入记录ID", required = true) String id,
                                                        @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request confirm import distribute,{}", id);
        dataImportService.confirmImportDistribute(id, token);
        return ResponseEntity.ok().build();
    }
}
